package Java100_1006.operations;

import Java100_1006.Book;
import Java100_1006.BookDao;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work() {
        System.out.println("新增书籍！");
        Scanner scanner  = new Scanner(System.in);
        System.out.println("请输入书名: ");
        String bookName = scanner.next();
        System.out.println("请输入作者: ");
        String author = scanner.next();
        System.out.println("请输入价格:");
        int price = scanner.nextInt();
        System.out.println("请输入类别:");
        String type = scanner.next();
        //假设新增书籍都是未借出的状态
        Book book = new Book();
        book.setName(bookName);
        book.setAuthor(author);
        book.setPrice(price);
        book.setType(type);
        BookDao bookDao = new BookDao();
        boolean ret = bookDao.add(book);
        if(ret){
            System.out.println("新增书籍成功");
        }else{
            System.out.println("新增书籍失败!");
        }
    }
}
